package com.tie.catalogo;

import java.util.ArrayList;

import android.app.Fragment;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.os.Environment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

public class Fragment_detalle extends Fragment {

	MySQLiteHelper DAO;
	ArrayList<Bitmap> imagenesCatalogo;
	TextView Tittle;
	TextView Desc;
	ImageView img;
	View vista;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		vista = inflater.inflate(R.layout.fragment_detalle, container, false);
		Tittle = (TextView) vista.findViewById(R.id.TitleFragD);
		Desc = (TextView) vista.findViewById(R.id.TxtFD);
		img = (ImageView) vista.findViewById(R.id.imgD);
		return vista;
	}

	public void mostrarID(String id) {
		DAO = new MySQLiteHelper(getActivity().getApplicationContext(),
				"database", null, 1);
		SQLiteDatabase db = DAO.getReadableDatabase();
		Cursor c = db.rawQuery("SELECT * FROM GOODS WHERE GOODID=" + id + ";",
				null);
		c.moveToFirst();
	    Tittle.setText(c.getString(1));
	    Desc.setText(c.getString(2));
	    System.out.println(c.getString(3));
	    try {
	    	img.setImageBitmap(new BitmapFactory().decodeFile(Environment
					.getExternalStorageDirectory()
					+ "/catalog/images/"
					+ c.getString(3)));
		} catch (Exception e) {
			e.printStackTrace();
		}
	    
	    DAO.close();
	    
		if (c != null) {
			System.out.println(c.getCount());
			c.moveToFirst();

		}
	}
}